package com.itheima.c01_api_period_duration;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

/**
 * 目标：了解jdk8提供的时间API，Period和Duration
 */
public class Test {
       public static void main(String[] args) {
        LocalDate girlFriend=LocalDate.of(1999,1,9);
        LocalDate mine=LocalDate.of(2000,10,10);
        //LocalDate now=LocalDate.now();//当前日期
        Period between=Period.between(girlFriend,mine);
        System.out.println("间隔天"+between.getDays());
        System.out.println("间隔年"+between.getYears());
        System.out.println("间隔月"+between.getMonths());
        System.out.println("总间隔月份"+between.toTotalMonths());
           System.out.println("------------------------");
           LocalDateTime start=LocalDateTime.of(2020,1,1,8,0,0,2);
           LocalDateTime end=LocalDateTime.of(2020,1,1,9,0,0,7);
           Duration between2= Duration.between(start,end);
            System.out.println("间隔小时"+between2.toHours());
            System.out.println("间隔分钟"+between2.toMinutes());
            System.out.println("间隔秒"+between2.getSeconds());
            System.out.println("间隔纳秒"+between2.toNanos());
           System.out.println("------------------------");
           Instant begin=Instant.now();
           String str="";
           for (int i = 0; i < 100000; i++) {
               str+=i;
           }
           Instant over=Instant.now();
           Duration between3=Duration.between(begin,over);
           System.out.println("耗时："+between3.toMinutes()+"分钟"+between3.getSeconds()+
                   "秒"+between3.toMillis()+"毫秒"+between3.toNanos()+"纳秒");
           System.out.println("------------------------");
           LocalDate now=LocalDate.now();
           System.out.println("当前时间："+now);
           Scanner sc=new Scanner(System.in);
           System.out.println("请输入您的生日：");
           String pattern="yyyy-MM-dd";
           DateTimeFormatter dtf=DateTimeFormatter.ofPattern(pattern);
           LocalDate birthday=LocalDate.parse(sc.nextLine(),dtf);
            Period between1=Period.between(birthday,now);
           System.out.println("间隔年："+between1.getYears()+"年"+between1.getMonths()+"月"+between1.getDays()+"天");
    }
}
